package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.user.IUserVerifyService;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import com.mall.user.dto.UserVerifyRequest;
import com.mall.user.dto.UserVerifyResponse;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Enzo Cotter on 2020/10/16.
 */
@RestController
public class UserVerifyController {

    @Reference
    IUserVerifyService userVerifyService;

    /**
     * 对用户进行邮箱激活
     * @param uid
     * @param username
     * @return
     */
    @GetMapping("user/verify")
    @Anoymous
    public ResponseData verify(@RequestParam String uid, @RequestParam String username){
        //判空
        if(uid == null || username == null || uid.isEmpty() || username.isEmpty()){
            return new ResponseUtil().setErrorMsg(SysRetCodeConstants.REQUISITE_PARAMETER_NOT_EXIST.getMessage());
        }
        UserVerifyRequest userVerifyRequest = new UserVerifyRequest();
        userVerifyRequest.setUserName(username);
        userVerifyRequest.setUuid(uid);

        UserVerifyResponse userVerifyResponse = null;
        try{
            //注册激活
            userVerifyResponse = userVerifyService.verify(userVerifyRequest);
        }catch (Exception e){
            return new ResponseUtil().setErrorMsg(SysRetCodeConstants.USER_INFOR_UPDATE_FAIL.getMessage());
        }
        if (!userVerifyResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
            return new ResponseUtil().setErrorMsg("注册失败！");
        }

        return new ResponseUtil().setData(null);
    }
}
